﻿using ATM.Common;
using ATM.Entities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ATM.DAO
{
    public class ValidateCardDAO
    {
        public static SqlConnection con;
        public static DataView ValidateCardDataView()
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM Cards", DataConnection.GetConnection());
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return new DataView(dt);
        }
        public static bool CheckPIN(string ID, string oldpin)
        {
            SqlCommand cmd = new SqlCommand(String.Format("SELECT * FROM Cards WHERE Cards.ID={0} AND Cards.Pin='{1}'", ID, oldpin), con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            da.Fill(table);
            if (table.Rows.Count == 0) return false;
            return true;
        }
    }
}
